import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
} from 'typeorm';
import {
  IsString,
  IsNotEmpty,
  IsEnum,
  IsNumber,
  MaxLength,
  IsOptional,
} from 'class-validator';
import { ReviewStatus } from '@/enum';
import { User } from '@/modules/users/entities/user.entity';
import { Artist } from './artist.entity';

@Entity({ name: 'artists_editions' })
export class ArtistEdition {
  @IsNumber()
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(
    _type => Artist,
    artist => artist.editions,
  )
  artist: Artist;

  @ManyToOne(
    _type => User,
    user => user.editedArtistEditions,
  )
  editor: User;

  @IsNotEmpty()
  @IsString()
  @Column({ type: 'text', nullable: true })
  description: string;

  @IsOptional()
  @IsString()
  @MaxLength(500)
  @Column({ type: 'character varying', length: 500, nullable: true })
  note: string;

  @IsNotEmpty()
  @IsEnum(ReviewStatus)
  @Column({
    type: 'enum',
    enum: ReviewStatus,
    default: ReviewStatus.UNDER_REVIEW,
  })
  reviewStatus: ReviewStatus = ReviewStatus.UNDER_REVIEW;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}
